package mwn.droidbus.ui;

import android.graphics.Color;

/**
 *		Colours class provides a set of colours to be used to colour different routes (and their busses). 
 */
public class Colours {

	/**
	 * Gets the colour in hexadecimal HTML notation. Numbering starts at 0. 
	 *
	 * @param number the number of unique routes that need unique colours
	 * @param divisions the index of a unique route as an offset in an ArrayList of Routes
	 * @return the colour as an integer
	 */
	public static int getColour(int number, int divisions) {
		//Input validation
		if ((number+1>divisions) || (divisions<1)) {
			return 0;
		}

		//uses the HSV colour space to evenly distribute the colours
		//Hue is a value between 0 and 360 degrees
		//typically 0 is red, 60 degrees yellow, 120 degrees green, 180 degrees cyan, 240 degrees blue, and 300 degrees magenta
		float[] hsv = new float[3];
		hsv[0] = (360 / divisions) * number; //hue
		hsv[1] = .7f; //saturation [0,1] - defines how gray the colour is - 0 indicates grey and 1 is the pure primary colour
		hsv[2] = 1; //value/brightness - Value is similar to luninance except it also varies the colour saturation.

		int colour = Color.HSVToColor(hsv);
		return colour;
	}

	/**
	 * Gets a String representation of the HTML colour.
	 *
	 * @param colour the integer representation of the colour
	 * @return the HTML colour as a String
	 */
	public static String getHTMLColour(int colour) {
		String col = Integer.toHexString(colour);
		return col.substring(2).toUpperCase();
	}
}
